home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.internetmci.com!xmission!news
- From: tknarr@xmission.com ( Todd Knarr )
- Newsgroups: comp.lang.c++
- Subject: Re: two tricky questions
- Date: 9 Jan 1996 02:26:19 GMT
- Organization: Chaos Central
- Message-ID: <4csjob$gsa@news.xmission.com>
- References: <4cnan0$gqv@news.xmission.com> <DKv098.7JE@cix.compulink.co.uk>
- Reply-To: tknarr@xmission.com ( Todd Knarr )
- NNTP-Posting-Host: slc31.xmission.com
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <DKv098.7JE@cix.compulink.co.uk>, henri@cix.compulink.co.uk ("Henry Andrew") writes:
- >It could be that some compilers do it as a bitwise copy but the compiler
- >I am currently using (IBM CSet++ on AIX) does a memberwise copy.
- >And in so doing, it seems to me, follow Stroustrup.
-
- That's because your class B has a copy constructor defined. Where you
- have defined a copy constructor memberwise initialization is possible
- and must be done. Bitwise copy occurs when members do not have a copy
- constructor.
-
- If you want to see it in action, try something like this:
-
- void main( void )
- {
- A a1, a2;
- a2 = a1;
- cout << a1._b._i << '\t' << a2._b._i << endl;
- }
-
- Since you didn't define copy assignment for class B, you'll see a
- different result ( assuming the compiler doesn't optimize out the
- assignment and do it by initialization instead ).
-
- --
- Todd Knarr : tknarr@xmission.com | finger for PGP public key
- | Member, USENET Cabal
-
- Seriously, I don't want to die just yet. I don't care how
- good-looking they are, I! don't! want! to! die!"
- -- Megazone ( UF1 )
-
-